package com.example.administrator.waitan.find.read;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.example.administrator.waitan.R;
import com.example.administrator.waitan.base.BaseActivity;
import com.example.administrator.waitan.find.FindFragment;
import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/1/12.
 */
public class ReadActivity extends BaseActivity  {
    private RequestQueue queue;
    private ArrayList<ReadInfo> infos;
    private String url = "http://www.mengxianyi.net/one/article.json";
    private ViewPager mViewPager;
    private ReadViewPagerAdapter mAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_read);
        final ReadProgressDialog dialog = new ReadProgressDialog(this,"开音乐了嘛...",R.anim.activity_in);
        dialog.show();
        mViewPager = (ViewPager) findViewById(R.id.vp_read);
        queue = Volley.newRequestQueue(this);
        ReadStringRequestUtf readStringRequestUtf = new ReadStringRequestUtf(url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                Gson gson = new Gson();
                infos = new ArrayList<>();
                ReadBeans beans = gson.fromJson(response, ReadBeans.class);
                for (int i = 0; i < beans.getData().size(); i++) {
                    infos.add(beans.getData().get(i));
                }
                mAdapter = new ReadViewPagerAdapter(ReadActivity.this,infos);
                mViewPager.setAdapter(mAdapter);
                dialog.dismiss();
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });
           queue.add(readStringRequestUtf);
    }

}
